package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysCloseDataVo;
import com.xjy.system.domain.bo.SysCloseDataQueryBo;
import com.xjy.system.domain.bo.SysCloseDataAddBo;
import com.xjy.system.domain.bo.SysCloseDataEditBo;
import com.xjy.system.service.ISysCloseDataService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 结账数据信息Controller
 *
 * @author xjy
 * @date 2022-03-10
 */
@Api(value = "结账数据信息控制器", tags = {"结账数据信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/data")
public class SysCloseDataController extends BaseController {

	private final ISysCloseDataService iSysCloseDataService;

	/**
	 * 查询结账数据信息列表
	 */
	@ApiOperation("查询结账数据信息列表")
	@PreAuthorize("@ss.hasPermi('system:data:list')")
	@GetMapping("/list")
	public TableDataInfo<SysCloseDataVo> list(@Validated SysCloseDataQueryBo bo) {
		return iSysCloseDataService.queryPageList(bo);
	}

	/**
	 * 导出结账数据信息列表
	 */
	@ApiOperation("导出结账数据信息列表")
	@PreAuthorize("@ss.hasPermi('system:data:export')")
	@Log(title = "结账数据信息", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<SysCloseDataVo> export(@Validated SysCloseDataQueryBo bo) {
		List<SysCloseDataVo> list = iSysCloseDataService.queryList(bo);
		ExcelUtil<SysCloseDataVo> util = new ExcelUtil<SysCloseDataVo>(SysCloseDataVo.class);
		return util.exportExcel(list, "结账数据信息");
	}

	/**
	 * 获取结账数据信息详细信息
	 */
	@ApiOperation("获取结账数据信息详细信息")
	@PreAuthorize("@ss.hasPermi('system:data:query')")
	@GetMapping("/{id}")
	public AjaxResult<SysCloseDataVo> getInfo(@NotNull(message = "主键不能为空")
											  @PathVariable("id") Long id) {
		return AjaxResult.success(iSysCloseDataService.queryById(id));
	}

	/**
	 * 新增结账数据信息
	 */
	@ApiOperation("新增结账数据信息")
	@PreAuthorize("@ss.hasPermi('system:data:add')")
	@Log(title = "结账数据信息", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody SysCloseDataAddBo bo) {
		return toAjax(iSysCloseDataService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改结账数据信息
	 */
	@ApiOperation("修改结账数据信息")
	@PreAuthorize("@ss.hasPermi('system:data:edit')")
	@Log(title = "结账数据信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody SysCloseDataEditBo bo) {
		return toAjax(iSysCloseDataService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除结账数据信息
	 */
	@ApiOperation("删除结账数据信息")
	@PreAuthorize("@ss.hasPermi('system:data:remove')")
	@Log(title = "结账数据信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iSysCloseDataService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
